#include <bits/stdc++.h>
using namespace std;

class Solution {
    int maxn = 0;
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_map<int, int> mp;
        for(auto& n: nums)
        {
            mp[n]++;
        }

        for(auto& x: mp)
        {
            if(mp.find(x.first-1) == mp.end())
            {
                int num = x.first;
                int curr = 1;
                while(mp.find(num+1) != mp.end())
                {
                    num += 1;
                    curr += 1;
                }
                maxn = max(maxn, curr);
            }
        }
        return maxn;
    }
};